<?php
/*php常用方法*/
class c {
	/*远程请求方法*/
	public function request_post($url = '', $post_data = array()) {
		if (empty($url)) {
			return false;
		}
		$o = "";
		foreach ($post_data as $k => $v) {
			$o .= "$k=" . urlencode($v) . "&";
		}
		$post_data = substr($o, 0, -1);
		$postUrl = $url;
		$curlPost = $post_data;
		$ch = curl_init(); //初始化curl
		curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
		curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
		curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
		curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
		curl_setopt($ch, CURLOPT_TIMEOUT, 20);
		$data = curl_exec($ch); //运行curl
		curl_close($ch);
		if ($data) {
			$data = json_decode($data, true);
		}
		return $data;
	}
	function getJson($url, $data = array(), $method = 'GET') {
		$ch = curl_init(); //1.初始化
		curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //3.请求方式
		//4.参数如下
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		if ($method == "POST") {
			//5.post方式的时候添加数据
			$data = json_encode($data);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);
		curl_close($ch);
		return json_decode($output, true);
	}

	function curlPost($url, $data, $method) {
		$ch = curl_init(); //1.初始化
		curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //3.请求方式
		//4.参数如下
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //https
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); //模拟浏览器
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate')); //gzip解压内容
		curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');

		if ($method == "POST") {
//5.post方式的时候添加数据
			$data = json_encode($data);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$tmpInfo = curl_exec($ch); //6.执行

		if (curl_errno($ch)) {
//7.如果出错
			return curl_error($ch);
		}
		curl_close($ch); //8.关闭
		return $tmpInfo;
	}
	/*php 加减乘除精度运算*/
	function yu(){

		$a=10;
		$b=3;

		//除法
		
		$result = bcdiv($a, $b, 2);
		echo $result //3.33

		//乘法
		
		echo bcmul($a, $bn,2);//30.00

		//加法

		ech bcadd($a, $b,2); //13.00	

		//减法
		
		echo bcscale($a,$b);//




	}


}

?>